package com.qianchang.microfinance.view.mine.intention;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.LoanIntentBean;
import com.qianchang.microfinance.global.ConstantAppInfo;
import com.qianchang.microfinance.view.base.BaseRecyclerAdapter;
import com.dm.library.widgets.element.DTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jinbailiang on 2017/8/15.
 */

public class LoanIntentionAdapter extends BaseRecyclerAdapter<LoanIntentBean> {


    public LoanIntentionAdapter(Context context) {
        super(context, BaseRecyclerAdapter.ONLY_FOOTER);
    }

    @Override
    protected MyViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_my_loan, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, final LoanIntentBean item, final int position) {
        MyViewHolder vh = (MyViewHolder) holder;
        vh.tvMoney.setTextContent(item.getApplyAmount());
        vh.tvStatus.setTextContent(item.getStatusDesc());
        vh.tvPeriod.setTextContent(item.getDeadline() + "个月");
        String createTime = item.getCreateTime();
        if (null != createTime && createTime.length() > 10) {
            createTime = createTime.substring(0, 10);
        }
        vh.tvApplyDate.setTextContent(createTime);
        vh.tvSureAgreement.setVisibility(View.GONE);
        vh.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, LoanIntentDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString(ConstantAppInfo.PROJECT_ID, item.getId());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });

    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_money)
        DTextView tvMoney;
        @BindView(R.id.tv_period)
        DTextView tvPeriod;
        @BindView(R.id.tv_apply_date)
        DTextView tvApplyDate;
        @BindView(R.id.tv_status)
        DTextView tvStatus;
        @BindView(R.id.tv_sure_agreement)
        DTextView tvSureAgreement;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
